Let's give the player a point for catching something.
Go to and drag out Add Value. Drop it inside the collision event.
Change the name of the variable to score.
Now, each time that the sprite catches an item, the value of score will go up by 1.
To navigate the page using the TAB key, first press ESC to exit the code editor.
stage.set_background("schoolhallway")
sprite = codesters.Sprite("person8")
stage.set_gravity(4)
stage.disable_floor()
sprite.set_gravity_off()
sprite.go_to(0, -220)
score = 0
score_board = codesters.Display(score)
my_info = ["cellphone", "address", "birthdate"]
def left_key():
sprite.move_left(20)
# add other actions...
stage.event_key("left", left_key)
def right_key():
sprite.move_right(20)
# add other actions...
stage.event_key("right", right_key)
def interval():
x = random.randint(-230, 230)
info_img = random.choice(my_info)
# sprite = codesters.Sprite("image", x, y)
info = codesters.Sprite(info_img, x, 275)
# add any other actions...
stage.event_interval(interval, 3)
def collision(sprite, hit_sprite):
# add any other actions...
global score
stage.remove_sprite(hit_sprite)
sprite.event_collision(collision)
t = codesters.Teacher()
try:
tval1 = t.find_text('+=')[0][1]
tval2 = t.find_text('+=')[0][0]
tval2a = t.get_indent_at_line(tval2)
except:
tval1 = "DNE"
tval2 = "DNE"
tval2a = "DNE"
t1 = TestObjective()
t1.add_success('score' in tval1 and tval2a == 4, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add an Add Value command to your Collision Event?")
t1.add_failure('score' not in tval1, "Did you change the name of the variable to score?")
t1.add_failure(tval2a < 4, "Did you indent your Add Value command inside your Collision Event?")
t1.add_failure(tval2a > 4, "Oops! Make sure your only indent your Add Value command only 4 spaces inside your event!")
tester = TestManager()
tester.add_test_list([t1])
tester.run_tests()
tester.display_first_feedback()
Are you already running a Codesters project in another tab or window?
Micro:bit can only connect to one web page at a time.
Try stopping other Codesters projects or closing
other tabs or windows that may be using your Micro:bit.
If that doesn't fix the problem try disconnecting your Micro:bit,
reloading this page, and reconnecting your Micro:bit.